<?php
if (isset($_REQUEST["sendnew"]))
{
	$success = true;
	$validator = array("bookingtime" => "isPostedDatetime",
						"amount" => "isPostedInteger",
						"accountid" => "isPosted",
						"categoryid" => "isPosted");

	if (validateForm($validator, $_REQUEST))
	{
		if (!setNewTransaction($_REQUEST["accountid"], $_SESSION["userid"], $_REQUEST["direction"], $_REQUEST["amount"], $_REQUEST["description"], $_REQUEST["bookingtime"], $_REQUEST["categoryid"], $_REQUEST["tags"], $_REQUEST["partnername"]))
		{
			$success = false;
		}
	}
	else
	{
		$success = false;
	}
}

$accounts = getAccounts($_SESSION["userid"]);
$categoryTree = getCategoryTree("NULL", 1, false);
?>
			<div id="textcontainer">
				<h2>Új tranzakció</h2>
				<p>
					<?php if (isset($success) && !$success) print "<div class=\"errortitle\">valami nem sikerult!</div>";?>
					<form name="newtransaction" action="<?php print $_SERVER["SCRIPT_NAME"] . "?" . $_SERVER["QUERY_STRING"];?>" method="post">
						számla: <select name="accountid">
<?php
	foreach ($accounts as $acc)
	{
		print "<option value=\"" . $acc["id"] . "\"" . (isset($_REQUEST["accountid"]) && !$success && ($_REQUEST["accountid"] == $acc["id"])?" selected=\"selected\"":"") . ">" . $acc["name"] . "</option>";
	}
?>
						</select><br/>
						irány: <select name="direction">
						<option value="E" selected="selected">kiadás</option>
						<option value="I">bevétel</option>
						</select><br/>
						összeg: <input type="text" name="amount"<?php print (isset($_REQUEST["amount"]) && !$success)?' value="' . $_REQUEST["amount"] . '"':"";?>/><br/>
						partner: <input type="text" name="partnername"<?php print (isset($_REQUEST["partnername"]) && !$success)?' value="' . $_REQUEST["partnername"] . '"':"";?>/><br/>
						leírás: <textarea name="description"><?php print (isset($_REQUEST["description"]) && !$success)?$_REQUEST["description"]:"";?></textarea><br/>
						időpont: <input type="text" name="bookingtime"<?php print (isset($_REQUEST["bookingtime"]) && !$success)?' value="' . $_REQUEST["bookingtime"] . '"':"";?>/><i>(pl. 2005-10-12 15:00:00)</i><br/>
						kategória: <select name="categoryid">
						<option value="">- válassz -</option>
<?php
	foreach ($categoryTree as $category)
	{
		print "<option value=\"" . $category["category"]["id"] . "\"" . (isset($_REQUEST["categoryid"]) && !$success && ($_REQUEST["categoryid"] == $category["category"]["id"])?" selected=\"selected\"":"") . ">" . $category["category"]["name"] . "</option>";
		if (isset($category["subcategoryList"]))
		{
			foreach($category["subcategoryList"] as $subcategory)
			{
				print "<option value=\"" . $subcategory["category"]["id"] . "\"" . (isset($_REQUEST["categoryid"]) && !$success && ($_REQUEST["categoryid"] == $subcategory["category"]["id"])?" selected=\"selected\"":"") . ">&nbsp;&nbsp; - " . $subcategory["category"]["name"] . "</option>";
			}
		}
	}
?>
						</select><br/>
						címke: <input type="text" name="tags"<?php print (isset($_REQUEST["tags"]) && !$success)?' value="' . $_REQUEST["tags"] . '"':"";?>/><br/>
						<input type="submit" name="sendnew" value="Ment"/>
					</form>
				</p>
			</div>
			<!---->
